package com.sinping.qh.query.notice;

import com.sinping.qh.query.base.Operator;
import com.sinping.qh.query.base.QueryParams;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Field;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wupeng
 * @create 2018/5/30
 */
@Data
public class NoticeBookQuery implements QueryParams, Serializable {
    private static final long serialVersionUID = 6776613649986351510L;

    /**
     * 通知书编号
     */
    private String noticeNo;
    /**
     * 接收单位
     */
    private String noticeReceiveUnitId;
    /**
     * 已下发通知书的时间
     */
    private Date noticeSendDateStart;

    private Date noticeSendDateEnd;
    /**
     * 下发部门
     */
    private String noticeSendDepart;
    /**
     * 通知书状态
     */
    private List<String> noticeStatus;
    /**
     * 方案状态(通知书下发之前，方案状态为空)
     */
    private String noticeCaseStatus;

    /**
     * 接收院系,权限
     */
    private List<String> noticeReceiveUnitIdList;

    static Map<String, String> aliasMap = new HashMap<>();
    static Map<String, Operator> operatorMap = new HashMap<>();

    static {

        aliasMap.put("noticeSendDateStart", "notice_send_date");
        aliasMap.put("noticeSendDateEnd", "notice_send_date");
        aliasMap.put("noticeNo", "notice_no");
        aliasMap.put("noticeReceiveUnitId", "notice_receive_unit_id");
        aliasMap.put("noticeSendDepart", "notice_send_depart");
        aliasMap.put("noticeStatus", "notice_status");
        aliasMap.put("noticeCaseStatus", "notice_case_status");
        /**
         * 接收院系,权限
         */
        aliasMap.put("noticeReceiveUnitIdList", "notice_receive_unit_id");

        operatorMap.put("noticeSendDateStart", Operator.gte);
        operatorMap.put("noticeSendDateEnd", Operator.lte);
        operatorMap.put("noticeNo", Operator.eq);
        operatorMap.put("noticeReceiveUnitId", Operator.eq);
        operatorMap.put("noticeSendDepart", Operator.regex);
        operatorMap.put("noticeStatus", Operator.in);
        operatorMap.put("noticeCaseStatus", Operator.eq);
        /**
         * 接收院系,权限
         */
        operatorMap.put("noticeReceiveUnitIdList", Operator.in);
    }


    @Override
    public String getAlias(String fieldName) {
        return aliasMap.getOrDefault(fieldName, fieldName);
    }

    @Override
    public Operator getOperators(String fieldName) {
        return operatorMap.getOrDefault(fieldName, Operator.eq);
    }
}
